import 'package:flutter/material.dart';
import 'package:flutter_application_cyber/pages/Message/cn_follow_list_page.dart';
import 'package:flutter_application_cyber/pages/Message/cn_message_list_page.dart';

class CnMessagePage extends StatefulWidget {
  const CnMessagePage({Key? key}) : super(key: key);

  @override
  State<CnMessagePage> createState() => _CnMessagePageState();
}

class _CnMessagePageState extends State<CnMessagePage> {
  int selectIndex = 0;
  final List<Widget> _pages = [
    const CnMessageListPage(),
    const CnFollowListPage()
  ];
  final PageController _pageController = PageController(initialPage: 0);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage('images/icon_page_bg_1.png'), fit: BoxFit.fill),
        ),
        child: Column(
          children: [
            Container(
              margin: EdgeInsets.only(top: 60, left: 20, right: 20),
              height: 52,
              width: double.infinity,
              decoration: BoxDecoration(
                  image: DecorationImage(
                      image: AssetImage('images/icon_btn_bg.png'),
                      fit: BoxFit.fill)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  InkWell(
                    onTap: () {
                      _pageController.jumpToPage(0);

                      setState(() {
                        selectIndex = 0;
                      });
                    },
                    child: Container(
                      width: 127,
                      height: 40,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              image:
                                  AssetImage('images/icon_coin_bg_mine.png'))),
                      child: Text(
                        'Messages',
                        style: TextStyle(
                            fontSize: 18,
                            color: selectIndex == 0
                                ? Color(0xFF1C0D15)
                                : Color(0x80000000)),
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      _pageController.jumpToPage(1);
                      setState(() {
                        selectIndex = 1;
                      });
                    },
                    child: Container(
                      width: 127,
                      height: 40,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              image:
                                  AssetImage('images/icon_coin_bg_mine.png'))),
                      child: Text(
                        'Follow',
                        style: TextStyle(
                            fontSize: 18,
                            color: selectIndex == 1
                                ? Color(0xFF1C0D15)
                                : Color(0x80000000)),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Expanded(
                child: Padding(
                    padding: const EdgeInsets.only(top: 0, left: 0, right: 0),
                    child: MediaQuery.removePadding(
                        removeTop: true,
                        context: context,
                        child: PageView.builder(
                            controller: _pageController,
                            itemCount: _pages.length,
                            onPageChanged: (int index) {
                              setState(() {
                                selectIndex = index;
                              });
                            },
                            itemBuilder: (BuildContext context, int index) {
                              return _pages[index];
                            }))))
          ],
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _pageController.dispose();
  }
}
